<!DOCTYPE html>
<html>
<head>
    <title>添加药品--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }

    </style>
</head>
<body>
<form id="myForm" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">药品编号</td>
            <td><input type="text" id="id" name="id" readonly="readonly"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">图片</td>
            <td><img id="logo" name="logo" src="/images/uploadFile/"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">进价</td>
            <td><input type="text" id="inPrice" name="inPrice" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">售价</td>
            <td><input type="text" id="outPrice" name="outPrice"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">药品名称</td>
            <td><input type="text" id="drugName" name="drugName" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">药品类型</td>
            <td>
                <label>
                    <select id="drugType" name="drugType">
                        <option value="">请选择药品类型</option>
                        <option value="中药">中药</option>
                        <option value="西药">西药</option>
                        <option value="处方">处方</option>
                        <option value="非处方">非处方</option>
                    </select>
                </label>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">简单描述</td>
            <td><input type="text" id="description" name="description"/></td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">保质期</td>
            <td><input type="text" id="quality" name="quality" value="36"/>月</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">详细描述</td>
            <td><textarea id="detailDescription" name="detailDescription"></textarea></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">生产厂商</td>
            <td><textarea id="factory" name="factory"></textarea></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">服用说明</td>
            <td><input type="text" id="instruction" name="instruction" value=""/></td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><textarea id="note" name="note"></textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button onclick="update()" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;
                    <button onclick="black()" class="btn btn-success" type="button">返回列表</button>
                </center>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">

    $(function () {
        show();
    })

    function show(){
        //获取url
        (function($){
            $.getUrlParam
                = function(name)
            {
                var reg
                    = new RegExp("(^|&)"+
                    name +"=([^&]*)(&|$)");
                var r
                    = window.location.search.substr(1).match(reg);
                if (r!=null) return unescape(r[2]); return null;
            }
        })(jQuery);
        var id = $.getUrlParam('id');
        $.ajax({
            type:"GET",
            url: "/drug/getDrupById?id="+id,
            success: function(vo){
                $("#id").val(vo.id);
                $("#logo").attr("src",vo.img);
                $("#inPrice").val(vo.inPrice);
                $("#outPrice").val(vo.outPrice);
                $("#drugName").val(vo.drugName);
                $("#drugType").val(vo.drugType);
                $("#description").val(vo.description);
                $("#quality").val(vo.quality);
                $("#detailDescription").val(vo.detailDescription);
                $("#factory").val(vo.factory);
                $("#instruction").val(vo.instruction);
                $("#note").val(vo.note);
            }
        });
    }
    function black() {
        window.location.href="/Medicine/index.html";
    }

    function update(){
        if($("#inPrice").val()==""||$("#outPrice").val()=="" || $("#drugName").val()==""
            ||$("#drugType").val()==""||$("#quality").val()==""){
            alert("有必要值为空");
            return false;
        }
        $.ajax({
            type:"POST",
            url:"/drug/updateDrug",
            data:$("#myForm").serialize(),
            dataType:"json",
            success: function(vo){
                alert(vo.msg);
                if(vo.code==200) {
                    black();
                }
            }
        });
    }
</script>
</body>
</html>